// pages/practice/practice.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    all:0,
    allright:0,
    drill: {
      test1: {
        id: 1,
        title: "数字运算",
        tip: "下列数字中，前后两个数字之和为10的数对为？(换行不计)",
        select: [0, 0, 0, 0],
        text: "",
        x:0,
      },
      test2: {
        id: 2,
        title: "找不同",
        tip: "下列字母中，的数量为？",
        select: [0, 0, 0, 0],
        text: "",
        x: 0,
      },
      test3: {
        id: 3,
        title: "苏尔特方格",
        tip: "下列表格中1-25不含有的数字为？",
        select: [0, 0, 0, 0],
        text: "",
        x: 0,
      }
    }
  },
  drill_test3: function () {
    var that = this;
    var tab = [1, 2, 3, 4, 5,
      6, 7, 8, 9, 10,
      11, 12, 13, 14, 15,
      16, 17, 18, 19, 20,
      21, 22, 23, 24, 25];
    var text = "";
    var x = 0;
    var n = 25;
    var i = 0;
    var j = 0;
    for(;i<5;i++){
      for(j=0;j<5;j++){
        if(i==2&&j==2){
          var ran = Math.floor(Math.random() * n);
          x = tab[ran];
          text += " ";
          for (; ran < 25; ran++) {
            tab[ran] = tab[ran+1];
          }
        }else{
          var ran = Math.floor(Math.random() * n);
          text += tab[ran];
          for(;ran<25;ran++){
            tab[ran] = tab[ran+1];
          }
        }
        n--;
        text += "\t";
      }
      text += "\n\n";
    }
    var select = "drill.test3.text";
    that.setData({[select]:text});
    console.log(text);
    //答案
    var ra = Math.floor(Math.random() * 10) % 4;
    var select = "drill.test3.select[" + ra + "]";
    this.setData({ [select]: x });
    select = "drill.test3.x";
    this.setData({ [select]: x });
    var xx = [x, 0, 0, 0];
    j = 1;
    for (i = 0; i < 3; i++) {
      ra++;
      var f = false;
      if (ra == 4) {
        ra = 0;
      }
      do {
        xx[j] = Math.floor(Math.random() * 25);
        var k = 0;
        for (; k < j; k++) {
          if (xx[k] == xx[j]) {
            f = true;
            break;
          } else {
            f = false;
          }
        }
      } while (f);
      select = "drill.test3.select[" + ra + "]";
      that.setData({ [select]: xx[j] });
      j++;
    }
    console.log("答案是：" + x);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.drill_test3();

  },
  set_logs:function(){
    wx.navigateTo({
      url: '/pages/set_logs/set_logs',
      success: function (res) { }
    })
  },
  back: function () {
    wx.navigateBack({

    })
  },
  next:function(){
    this.setData({ all: this.data.all + 1 });
    this.setData({ allright: this.data.allright + 1 });
    this.drill_test3();
  },
  tip: function () {
    this.setData({ all: this.data.all + 1 });
    wx.showModal({
      title: '提示',
      content: '答错了！',
      
    })
  },
  drill_test1: function (){
    var string = "";
    var i = 0;
    var j = 0;
    var x = 0;
    for (i = 0; i < 4; i++) {
      var p = -1;
      var q = -1;
      for (j = 0; j < 10; j++) {
        p = q;
        q = Math.floor(Math.random() * 10);
        if (p != -1 && p + q == 10) {
          x++;
        }
        string += q;
        string += " ";
      }
      string += "\n\n";
    }
    var text = "drill.test1.text";
    var ra = Math.floor(Math.random() * 10) % 4;
    var select = "drill.test1.select[" + ra + "]";
    this.setData({ [text]: string });
    this.setData({ [select]: x });
    select = "drill.test1.x";
    this.setData({ [select]: x });
    //生成选项不相同的其他三个选项
    var xx = [x, 0, 0, 0];
    j = 1;
    for (i = 0; i < 3; i++) {
      ra++;
      var f = false;
      if (ra == 4) {
        ra = 0;
      }
      do {
        xx[j] = Math.floor(Math.random() * 10);
        var k = 0;
        for (; k < j; k++) {
          if (xx[k] == xx[j]) {
            f = true;
            break;
          } else {
            f = false;
          }
        }
      } while (f);
      select = "drill.test1.select[" + ra + "]";
      this.setData({ [select]: xx[j] });
      j++;
    }
    console.log("答案是：" + x);
  },
  drill_test2: function () {
    var string = "";
    var i = 0;
    var j = 0;
    var x = 0;
    var num = [["V", "W"], ["O", "Q"], ["1", "7"], ["去", "丢"]];
    var num1 = Math.floor((Math.random() * num.length));
    var a = [num1];
    var d = num[a];
    var f = d[0];
    var string2 = "drill.test2.tip";
    this.setData({ [string2]: '下列字母中，"' + f + '"的数量为？' });
    for (i = 0; i < 2; i++) {
      for (j = 0; j < 10; j++) {
        var index = d[Math.floor((Math.random() * d.length))];
        if (index == f) {
          x++;
        }
        string += index;
      }
      string += "\n\n";
    }
    var text = "drill.test2.text";
    this.setData({ [text]: string });
    var select = "drill.test2.x";
    this.setData({ [select]: x });
    //正确答案任选一个选项放置
    var ra = Math.floor(Math.random() * 10) % 4;
    select = "drill.test2.select[" + ra + "]";
    this.setData({ [select]: x });
    //生成选项不相同的其他三个选项
    var xx = [x, 0, 0, 0];
    j = 1;
    for (i = 0; i < 3; i++) {
      ra++;
      var f = false;
      if (ra == 4) {
        ra = 0;
      }
      do {
        xx[j] = Math.floor((Math.random() * 10) + 5);
        var k = 0;
        for (; k < j; k++) {
          if (xx[k] == xx[j]) {
            f = true;
            break;
          } else {
            f = false;
          }
        }
      } while (f);
      select = "drill.test2.select[" + ra + "]";
      this.setData({ [select]: xx[j] });
      j++;
    }
    console.info(x);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})